package com.mlz.mlzmall.ui.activity.act.personal.userLogin;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Response;
import com.google.gson.Gson;
import com.mlz.mlzmall.R;
import com.mlz.mlzmall.bean.PostLogin;
import com.mlz.mlzmall.bean.UserBean;
import com.mlz.mlzmall.ui.activity.act.base.TopTitleView;
import com.mlz.mlzmall.ui.activity.act.main.MainActivity;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.AgainLoginService;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.LoginUtils;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.MyCenterUtils;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.ProgessTools;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.RequestUtils;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.VolleyBaseActivity;
import com.mlz.mlzmall.ui.activity.act.personal.PersonalActivity;
import com.mlz.mlzmall.ui.activity.act.personal.myActivityPack.ShareActivity;
import com.mlz.mlzmall.ui.model.StringTools;
import com.mlz.mlzmall.ui.utils.mlz.ConfigInfo;
import com.mlz.mlzmall.ui.utils.mlz.Constans;
import com.mlz.mlzmall.ui.utils.mlz.DataSharedPress;
import com.mlz.mlzmall.ui.utils.mlz.URL;
import com.mlz.mlzmall.ui.utils.util.ACache;
import com.mlz.mlzmall.ui.utils.util.CacheUtils;
import com.mlz.mlzmall.ui.utils.util.LogUtils;
import com.mlz.mlzmall.ui.utils.util.SharedUtils;
import com.mlz.mlzmall.ui.utils.vali.AbStrUtil;
import com.sina.weibo.sdk.auth.WeiboAuth;
import com.sina.weibo.sdk.auth.sso.SsoHandler;
import com.tencent.connect.auth.QQAuth;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;

/**
 * 登录页面
 * Created by Administrator on 2016/5/18.
 */
public class LoginActivity extends VolleyBaseActivity implements View.OnClickListener {
    private static final String TGA = "LoginActivity";
    //    private TelephonyManager telephonyManager;
    UserBean userBean;
    RestTemplate restTemplate;
    DataSharedPress sharedPress;
    Intent aaintent;
    private UserDbAdapter mDbHelper;
    // 微信窗口传过来的个人登录信息
    ResposeGetPersonInfo resposeGetPersonInfo;

    private Tencent mTencent;
    public QQAuth mQQAuth;
    int type;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_activity);//跳转到登录界面
        sharedPress = DataSharedPress.getSharedPress(getApplication(), "userInfo");
        restTemplate = new RestTemplate();
        userBean = new UserBean();
        aaintent = getIntent();
        type = aaintent.getIntExtra("type", 0);
        mDbHelper = new UserDbAdapter(this);
        mDbHelper.open();
        assignViews();
        setViewContent();
        setViewClickListener();
        //三方登录的参数（绑定的用户）
        AuthLoginInfo();
        // 三方登录参数（未知用户先登录再判断，未绑定去绑定；否则直接登录）
        AuthLoginTest();
        //QQ 登录数据初始化
        QQInitData();
    }


    private TopTitleView loginTopTitle;
    private EditText etPhoneNumber;
    private EditText etPwd;
    private Button btnLogin;
    private TextView tvToRegist;
    private TextView tvForgetPwd;
    private ImageView ivWechatToLogin;
    private ImageView ivQqToLogin;
    private ImageView ivBlogToLogin;

    private void assignViews() {
        loginTopTitle = (TopTitleView) findViewById(R.id.login_top_title);
        etPhoneNumber = (EditText) findViewById(R.id.et_phone_number);
        etPwd = (EditText) findViewById(R.id.et_pwd);
        btnLogin = (Button) findViewById(R.id.btn_login);
        tvToRegist = (TextView) findViewById(R.id.tv_to_regist);
        tvForgetPwd = (TextView) findViewById(R.id.tv_forget_pwd);
        ivWechatToLogin = (ImageView) findViewById(R.id.iv_wechat_to_login);
        ivQqToLogin = (ImageView) findViewById(R.id.iv_qq_to_login);
        ivBlogToLogin = (ImageView) findViewById(R.id.iv_blog_to_login);
        etPhoneNumber.setText("");
        etPwd.setText("");
        etPhoneNumber.setSelection(etPhoneNumber.getText().length());
        etPwd.setSelection(etPwd.getText().length());
    }

    private void setViewContent() {
        loginTopTitle.setLeftButtonContent(null, R.mipmap.pic_2_1_btn_back, null);
        loginTopTitle.setTitleButtonContent("登录", null, null);
    }

    private void setViewClickListener() {
        loginTopTitle.setOnLeftButtonClickListener(new TopTitleView.OnLeftButtonClickListener() {
            @Override
            public void onLeftBtnClick(View button) {
                finish();
                LoginActivity.this.overridePendingTransition(R.anim.right_in, R.anim.right_out);
            }
        });
        tvToRegist.setOnClickListener(this);
        tvForgetPwd.setOnClickListener(this);
        btnLogin.setOnClickListener(this);
        ivWechatToLogin.setOnClickListener(this);
        ivQqToLogin.setOnClickListener(this);
        ivBlogToLogin.setOnClickListener(this);
    }

    // 刚刚绑定的用户,登录
    private void AuthLoginInfo() {
        if ("FROM_RELATION_PHONE_ACTIVITY".equals(aaintent.getAction())) {
            ArrayList array = aaintent.getCharSequenceArrayListExtra("data");
            PostLoginOauth postLoginOauthGet = (PostLoginOauth) array.get(0);
            Log.i("info", "postLoginOauthGet--->" + postLoginOauthGet.toString());
            //三方登录跳转页面
            loginAuth(postLoginOauthGet);
        }
    }

    // 未知用户
    private void AuthLoginTest() {
        if ("FROM_WX_ENTRY_ACTIVITY".equals(aaintent.getAction())) {
            ArrayList array = aaintent.getCharSequenceArrayListExtra("data");
            resposeGetPersonInfo = (ResposeGetPersonInfo) array.get(0);
            Log.i("info", "res" + resposeGetPersonInfo.toString());
            // post请求参数
            PostLoginOauth postLoginOauth = new PostLoginOauth();
            postLoginOauth.setType("weChat");
            postLoginOauth.setLoginId(resposeGetPersonInfo.getUnionid());
            postLoginOauth.setAvatar(resposeGetPersonInfo.getHeadimgurl());
            postLoginOauth.setName(resposeGetPersonInfo.getNickname());
            postLoginOauth.setAddress(resposeGetPersonInfo.getCity());
            postLoginOauth.setBirthday("");
            postLoginOauth.setDescription("");
            postLoginOauth.setGender(resposeGetPersonInfo.getSex());
            postLoginOauth.setIsActive("");
            // 获取DeviceId
            TelephonyManager telephonyManager = (TelephonyManager) LoginActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
            postLoginOauth.setDeviceId(telephonyManager.getDeviceId().toString());
            // 去登陆
            loginAuth(postLoginOauth);

        }
    }

    private String loginName, loginPwd;

    @Override
    public void onClick(View v) {
        final Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.btn_login://登录
                loginName = etPhoneNumber.getText().toString();
                loginPwd = etPwd.getText().toString();
                if ((loginName == null || loginName.equalsIgnoreCase("")) || (loginPwd == null || loginPwd.equalsIgnoreCase(""))) {
                    Toast.makeText(LoginActivity.this, "用户名或密码不能为空", Toast.LENGTH_SHORT).show();
                    return;
                } else if (AbStrUtil.isMobileNO(loginName)) {
                    // 登录进度条显示
                    ProgessTools.showProgressDialog(LoginActivity.this, "亲，正在努力为你登录");
                    // 登录
                    login();
                } else {
                    Toast.makeText(LoginActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                break;
            case R.id.tv_to_regist://我要注册
                intent.setClass(LoginActivity.this, RegistActivity.class);
                enterAtivityNotFinish(intent);
                break;
            case R.id.tv_forget_pwd://忘记密码
                intent.setClass(LoginActivity.this, ForgetPasswordActivity.class);
                enterAtivityNotFinish(intent);
                break;
            case R.id.iv_wechat_to_login:
                //  app注册到微信
                IWXAPI api = WXAPIFactory.createWXAPI(LoginActivity.this, Constans.APP_ID, true);
                api.registerApp(Constans.APP_ID);
                // 发起授权请求登录
                final SendAuth.Req req = new SendAuth.Req();
                req.scope = "snsapi_userinfo";
                req.state = "wechat_sdk_demo_test";
                api.sendReq(req);
                break;
            case R.id.iv_qq_to_login:
                qqLogin();
                break;
            case R.id.iv_blog_to_login:
                WeiBoLogin();
                break;
        }
    }

    public void login() {
        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg.arg1 == 404) {
                    Toast.makeText(LoginActivity.this, "网络连接错误，请检查网络", Toast.LENGTH_SHORT).show();
                    ProgessTools.closeProgressDialog();
                } else {
                    if (msg.arg1 != 0) {
                        Toast.makeText(LoginActivity.this, "登录失败，用户名或密码错误", Toast.LENGTH_SHORT).show();
                        // 关闭进度条
                        ProgessTools.closeProgressDialog();
                    } else if (msg.arg1 == 0) {
                        Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                        //给个值判断是否登陆，和商品详情介绍的绿星星按钮结合判断
                        CacheUtils.putBoolean(LoginActivity.this, "Logined", true);
                        sharedPress.putBoolean("isFrist", true);
                        ACache mCache = ACache.get(getApplication());
                        mCache.put("phoneid", loginName);
                        mCache.put("islogin", "login");
                        if (StringTools.sharelogin == 1) {
                            Intent intent = new Intent();
                            intent.setClass(LoginActivity.this, ShareActivity.class);
                            intent.putExtra("promotionId", String.valueOf(SharedUtils.get(LoginActivity.this, "promotionId", 0)));
                            StringTools.shareid = 4;
                            startActivity(intent);
                        } else if (StringTools.sharelogin == 5) {
                           /* Intent intent = new Intent();
                            intent.setClass(LoginActivity.this, FreeTrialActivity.class);
                            intent.putExtra("promotionIdUrl", "http://test.m.mlzmall.com/Home/Share/appAward?promotion_id=" + String.valueOf(StringTools.promotionId));
                            startActivity(intent);*/
                        } else if (type == 100) {
                            Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                            startActivity(intent);
                        }
                        StringTools.updatashopping = 1234;
                        StringTools.phoneid = loginName;
                        Intent intent = new Intent(LoginActivity.this, AgainLoginService.class);
                        startService(intent);
                        // 关闭进度条
                        ProgessTools.closeProgressDialog();
                        Intent intent1 = new Intent(LoginActivity.this, PersonalActivity.class);
                        startActivity(intent1);
                        LogUtils.d("登录成功如果人session:" + ACache.get(mContext).getAsString("sessionKeyLogin"));
                        overridePendingTransition(R.anim.right_in, R.anim.left_out);
                    }

                }
                //  Log.i("info", "请求结果--->" + value);

            }
        };
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message message = handler.obtainMessage();
//                Bundle bundle = new Bundle();
                try {
                    // 创建一个restTemplate 对象
                    String sessionKeyLogin;
                    // 取到sessionKey
                    ACache mCache = ACache.get(getApplication());
                    String sessionKeyLogin1 = mCache.getAsString("sessionKeyLogin");
                    if (sessionKeyLogin1 == null) {
                        GetSession urlSession = restTemplate.getForObject(URL.SESSION.GET, GetSession.class);
                        String sessionKey = urlSession.getData().getSessionKey();
                        if (sessionKey != null) {
                            mCache.put("sessionKeyLogin", sessionKey);
                            sessionKeyLogin = sessionKey;
                        } else {
                            sessionKeyLogin = null;
                        }
                    } else {
                        sessionKeyLogin = sessionKeyLogin1;
                        mCache.put("sessionKeyLogin", sessionKeyLogin);
                    }
                    LogUtils.d("====检查session:" + ACache.get(mContext).getAsString("sessionKeyLogin"));
                    String telephony = mCache.getAsString("telephony");
                    System.out.println("telephony！！！！---->>" + telephony);
                    // post 请求登录
                    PostLogin postLogin = new PostLogin();
                    postLogin.setTelephone(loginName);//用户名
                    postLogin.setPassword(loginPwd);//密码
                    postLogin.setVcode("string");
                    postLogin.setDeviceId(telephony);

                    HttpHeaders requestHL = new HttpHeaders();
                    requestHL.set("Cookie", "JSESSIONID=" + sessionKeyLogin);
                    requestHL.setContentType(new MediaType("application", "json"));
                    HttpEntity<PostLogin> requestEntityLogin = new HttpEntity<PostLogin>(postLogin, requestHL);
                    ResponseEntity<ResposeLogin> responseLogin = restTemplate.exchange(URL.CUSTOMER.LOGIN, HttpMethod.POST, requestEntityLogin, ResposeLogin.class);
                    int ResultStatus = responseLogin.getBody().getStatus();
                    message.arg1 = ResultStatus;
                } catch (Exception e) {
                    message.arg1 = 404;

                    System.out.println("telephony@@@@@@---->>" + e.toString());
                    e.printStackTrace();
                } finally {
                    handler.sendMessage(message);
                }
            }
        }).start();
    }

    /**
     * 微博登录
     */

    private SsoHandler mSsoHandler;

    boolean isInstall() {
        try {
            LoginActivity.this.getPackageManager().getPackageInfo("com.sina.weibo", 0);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    class GetHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            try {
                WeiBoUser user = new Gson().fromJson(msg.obj.toString(), WeiBoUser.class);
                PostLoginOauth postLoginOauth = new PostLoginOauth();
                postLoginOauth.setType("weibo");
                postLoginOauth.setLoginId(user.getIdstr());
                postLoginOauth.setAvatar(user.getAvatar_large());
                postLoginOauth.setName(user.getName());
                postLoginOauth.setAddress(user.getLocation());
                postLoginOauth.setBirthday("");
                postLoginOauth.setDescription("");
                postLoginOauth.setGender(user.getGender());
                postLoginOauth.setIsActive("");
                // 获取DeviceId
                TelephonyManager telephonyManager = (TelephonyManager) LoginActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
                postLoginOauth.setDeviceId(telephonyManager.getDeviceId().toString());
                // 去登陆
                loginAuth(postLoginOauth);
            } catch (Exception e) {
            }

        }
    }

    // 三方登录跳转页面
    private void loginAuth(final PostLoginOauth postLoginOauthGet) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // 创建一个restTemplate 对象
                    final ACache mCache = ACache.get(getApplication());
                    HttpHeaders requestHL = new HttpHeaders();
                    requestHL.set("Cookie", "JSESSIONID=" + mCache.getAsString("sessionKeyAuth"));
                    requestHL.setContentType(new MediaType("application", "json"));
                    HttpEntity<PostLoginOauth> oAuthLogin = new HttpEntity<>(postLoginOauthGet, requestHL);
                    ResponseEntity<ResposeLogin> responseLoginAuth = restTemplate.exchange(URL.CUSTOMER.LOGIN_3RD_PARTY, HttpMethod.POST, oAuthLogin, ResposeLogin.class);
                    final int status = responseLoginAuth.getBody().getStatus();
                    final String msg = responseLoginAuth.getBody().getMsg();
                    runOnUiThread(new Runnable() {
                        @Override
                        //登录成功跳转页面
                        public void run() {
                            if (0 == status) {
                                //给个值判断是否登陆，和商品详情介绍的绿星星按钮结合判断
                                CacheUtils.putBoolean(LoginActivity.this, "Logined", true);
                                sharedPress.putBoolean("isFrist", true);

                                // 如果三方登录成功跳转页面,把个人信息传给 CenterUI
                                Intent intentToCenter = new Intent(LoginActivity.this, MainActivity.class);
                                intentToCenter.setAction("FROM_AUTHOR_LOGIN_SUCCESS");
                                ArrayList data = new ArrayList<>();
                                data.add(postLoginOauthGet);

                                intentToCenter.putCharSequenceArrayListExtra("data", data);
                                startActivity(intentToCenter);

                                mCache.put("sessionKeyLogin", mCache.getAsString("sessionKeyAuth"));
                                Log.i(TGA, "等三方登录成功的session:" + mCache.getAsString("sessionKeyLogin"));
                                mCache.put("phoneid", postLoginOauthGet.getLoginId());
                                StringTools.phoneid = postLoginOauthGet.getLoginId();
                                Intent intent = new Intent(LoginActivity.this, AgainLoginService.class);
                                startService(intent);
                                finish();
                            } else if (1113 == status) {
                                // 登录并反馈状态码，1113 该帐号未绑定-->去绑定
                                Intent intent = new Intent(LoginActivity.this, RelationPhoneActivity.class);
                                intent.setAction("FROM_LOGIN_ACTIVITY_TO_BUILDING");
                                ArrayList data = new ArrayList<>();
                                data.add(postLoginOauthGet);
                                intent.putCharSequenceArrayListExtra("data", data);
                                startActivity(intent);
                                finish();
                            } else {
                                Toast.makeText(getApplicationContext(), msg + status, Toast.LENGTH_LONG).show();
                                System.out.println("@@@@" + msg + status);
                            }
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }

    private void WeiBoLogin() {
        WeiboAuth.AuthInfo authInfo = new WeiboAuth.AuthInfo(LoginActivity.this, Constans.APP_KEY, Constans.REDIRECT_URL, Constans.SINA_SCOPE);
        WeiboAuth weiboAuth = new WeiboAuth(LoginActivity.this, authInfo);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    executeRequest(RequestUtils.getSession(mContext, new Response.Listener<String>() {
                        @Override
                        public void onResponse(String s) {
                            try {
                                JSONObject json = new JSONObject(s);
                                String sessionKey = json.getString("data");
                                //  把sessionKey 字符串保存到手机内部存储卡
                                ACache mCache = ACache.get(getApplication());
                                // 存放时间设定为1天,默认数量为1，更新会覆盖前面的值
                                if (sessionKey != null) {
                                    mCache.put("sessionKeyAuth", sessionKey, ACache.TIME_DAY);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    }));

                } catch (Exception e) {
                }
            }
        }).start();

        if (!isInstall()) {
            weiboAuth.anthorize(new MyAuthListener(LoginActivity.this, new GetHandler(), "LOGIN"));
        }

        if (isInstall()) {
            mSsoHandler = new SsoHandler(LoginActivity.this, weiboAuth);
            mSsoHandler.authorize(new MyAuthListener(LoginActivity.this, new GetHandler(), "LOGIN"));
        }

    }

    //初始化QQ登录
    private void QQInitData() {
        // Tencent类是SDK的主要实现类，通过此访问腾讯开放的OpenAPI。
        mQQAuth = QQAuth.createInstance(Constans.QQAPP_ID, this.getApplicationContext());
        // 实例化
        mTencent = Tencent.createInstance(Constans.QQAPP_ID, this);
    }

    //发起QQ登录
    IUiListener LoginListener;

    private void qqLogin() {
        // 登录
        if (!mQQAuth.isSessionValid()) {
            // 实例化回调接口
            LoginListener = new BaseUiListener() {
                @Override
                protected void doComplete(JSONObject values) {
                }
            };
            // "all": 所有权限，listener: 回调的实例
            mQQAuth.login(this, "all", LoginListener);

        } else {
            // 注销登录
            mQQAuth.logout(this);
        }

    }

    /**
     * 调用SDK封装好的借口，需要传入回调的实例 会返回服务器的消息
     */
    private class BaseUiListener implements IUiListener {
        /**
         * 成功
         */
        @Override
        public void onComplete(Object response) {
            doComplete((JSONObject) response);
            Gson gson = new Gson();
            ResponseQQInfo responseQQInfo = gson.fromJson(response.toString(), ResponseQQInfo.class);
            // 获取个人详细信息
            getDetailInfo(responseQQInfo);
        }

        /**
         * 处理返回的消息 比如把json转换为对象什么的
         *
         * @param values
         */
        protected void doComplete(JSONObject values) {

        }

        @Override
        public void onError(UiError e) {
            Toast.makeText(LoginActivity.this, e.toString(), Toast.LENGTH_LONG).show();
            System.out.println("@@@@!!!!" + e.toString());
        }

        @Override
        public void onCancel() {
            Toast.makeText(LoginActivity.this, "取消", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Tencent.onActivityResultData(com.tencent.connect.common.Constants.REQUEST_LOGIN, resultCode, data, LoginListener);

        if (requestCode == com.tencent.connect.common.Constants.REQUEST_API) {
            if (resultCode == com.tencent.connect.common.Constants.REQUEST_LOGIN) {
                Tencent.handleResultData(data, LoginListener);
            }
        }
        // SSO 授权回调
        // 重要：发起 SSO 登陆的 Activity 必须重写 onActivityResults
        if (mSsoHandler != null) {
            mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
        }
    }


    // 获取个人详细信息
    private void getDetailInfo(final ResponseQQInfo responseQQInfo) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // 创建一个restTemplate 对象
                    RestTemplate restTemplate = new RestTemplate();
                    String getDetailUrl = "https://graph.qq.com/user/get_user_info?access_token=" + responseQQInfo.getAccess_token() + "&oauth_consumer_key=1104922908&openid=" + responseQQInfo.getOpenid();
                    Gson gson = new Gson();
                    ResponseQQDetailInfo detailInfo = gson.fromJson(restTemplate.getForObject(getDetailUrl, String.class), ResponseQQDetailInfo.class);
                    Log.i("info", "detailInfo<--->" + detailInfo.toString());

                    //QQ 登录取SessionKey
                    GetSession urlSession = restTemplate.getForObject(URL.SESSION.GET, GetSession.class);
                    String sessionKey = urlSession.getData().getSessionKey();
                    //  把sessionKey 字符串保存到手机内部存储卡
                    ACache mCache = ACache.get(getApplication());
                    // 存放时间设定为1天,默认数量为1，更新会覆盖前面的值
                    if (sessionKey != null) {
                        mCache.put("sessionKeyAuth", sessionKey, ACache.TIME_DAY);
                    }

                    // 未知用户尝试QQ登录，如果已经绑定直接登录，否则去绑定--->
                    QQAuthLoginTest(responseQQInfo, detailInfo);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    // 未知用户尝试QQ登录，如果已经绑定直接登录，否则去绑定--->
    private void QQAuthLoginTest(ResponseQQInfo responseQQInfo, ResponseQQDetailInfo detailInfo) {
        // post请求参数
        PostLoginOauth postLoginOauth = new PostLoginOauth();
        postLoginOauth.setType("qq");
        postLoginOauth.setLoginId(responseQQInfo.getOpenid());
        postLoginOauth.setAvatar(detailInfo.getFigureurl_qq_2());
        postLoginOauth.setName(detailInfo.getNickname());
        postLoginOauth.setAddress(detailInfo.getCity());
        postLoginOauth.setBirthday("");
        postLoginOauth.setDescription("");
        postLoginOauth.setGender(1);
        postLoginOauth.setIsActive("");
        // 获取DeviceId
        TelephonyManager telephonyManager = (TelephonyManager) LoginActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
        postLoginOauth.setDeviceId(telephonyManager.getDeviceId().toString());
        // 去登陆
        loginAuth(postLoginOauth);
    }
}
